<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">

        <a-divider>基本信息</a-divider>
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input v-model="model.billNo" placeholder="请输入单据编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <a-input v-model="model.createTime" placeholder="请输入申请时间" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <select-user-by-dep :multi="false" v-model="model.proposer" disabled></select-user-by-dep>
              <!-- :disabled=formDisabled -->
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-divider>项目信息</a-divider>
        <a-row :gutter="48">
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <a-input
                v-if="formDisabled"
                readOnly
                @click.prevent="onDetail(model.projectId)"
                v-model="model.projectName"
                style="color: #1890FF; cursor: pointer;"
                placeholder="请选择项目名称"></a-input>
              <select-project-input
                v-else
                ref="projectInput"
                :disabled="formDisabled"
                v-model="model.projectId"
                :proDisabled="true"
                :allowClear="false"
                placeholder="请输入选择项目"
                :projectStatus="'2'"
                @input="projectChangeHandle" />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectNo">
              <a-input v-model="model.projectNo" :max-length="36" placeholder="请输入项目编号" disabled></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <select-user-by-dep :multi="false" v-model="model.undertaker" disabled></select-user-by-dep>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="managementTeam">
              <select-team-input
                v-model="model.managementTeam"
                :tdlx="1"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <j-dict-select-tag type="list" v-model="model.year" dictCode="year" placeholder="请选择业绩归属年度" disabled />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signUnit">
              <select-Company-input v-model="model.signUnit" placeholder="请选择签订单位" disabled />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
              <select-customer-input v-model="model.ownerUnit" placeholder="请选择业主单位" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="合同名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractId">
              <a-input
                v-if="model.contractId"
                readOnly
                @click.prevent="goDetail(model.contractId)"
                v-model="model.contractName"
                style="color: #1890FF; cursor: pointer;"
                placeholder="请选择合同名称"></a-input>
              <select-contract-manager-input
                v-else
                :muitFlag="true"
                v-model="model.contractId"
                htlx="1"
                @back="contractIdBack"
                :allList="true"
                :triggerChange="true"
                :showName="'1'"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item
              label="合同额(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="contractAmount"
            >
              <a-input-number
                :max="99999999"
                :min="0"
                v-model="model.contractAmount"
                placeholder="请输入合同额"
                style="width: 100%"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item
              label="实收款总额(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="totalAmountReceived"
            >
              <a-input-number
                :max="99999999"
                :min="0"
                v-model="model.totalAmountReceived"
                placeholder="实收款总额"
                style="width: 100%"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="无法按期回款原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reason">
              <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.reason" rows="4" placeholder="请输入无法按期回款原因"/>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-divider>任务信息</a-divider>
        <a-row :gutter="48">
          <a-table
            ref="table"
            size="middle"
            :scroll="{x:true}"
            :pagination="false"
            rowKey="id"
            :columns="taskItemColumns"
            :dataSource="taskDataSource">
            <!--                  class="j-table-force-nowrap">-->
            <!--                  <span slot="action" slot-scope="text, record">-->
            <!--                    <template v-if="!formDisabled">-->
            <!--                      <a @click="handleEdit4(record)">编辑</a>-->
            <!--                      <a-divider type="vertical"/>-->
            <!--                      <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete4(record.id)">-->
            <!--                        <a>删除</a>-->
            <!--                      </a-popconfirm>-->
            <!--                    </template>-->
            <!--                  </span>-->

          </a-table>
        </a-row>

        <a-divider>免责信息</a-divider>
        <a-row :gutter="48">
          <payback-disclaimer-disclaimer-info-list
            ref="disclaimerDetailList"
            :contractId="model.contractId"
            :managementTeam="model.managementTeam"
            :undertaker="model.undertaker"
            :disabled="formDisabled"
            :projectId="model.projectId"
          ></payback-disclaimer-disclaimer-info-list>
        </a-row>

        <a-divider>任务附件</a-divider>
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item prop="taskFile">
              <j-upload :disabled="formDisabled" v-model="model.taskFile"></j-upload>
              <!-- <a-button v-else icon="download" @click="viewFile(model.attachments)">文件列表</a-button> -->
            </a-form-model-item>
          </a-col>
        </a-row>

        <!-- <a-row :gutter="48">
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row> -->

      </a-form-model>

      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>

      <!-- 项目详情开始 -->
      <erp-project-report-modal ref="projectModalForm"></erp-project-report-modal>
      <!-- 项目详情结束 -->
      <erp-project-contract-manager-final-form ref="contractForm" ></erp-project-contract-manager-final-form>
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center; margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>
    <PaybackDisclaimerFormPrint v-if="formBpm" class="print_style" id="paybackDisclaimer" :formData="model" :formDataHistory="formData"></PaybackDisclaimerFormPrint>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { viewFile } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'

  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectContractManagerInput from '@/views/scy/components/SelectContractManagerInput'
  import moment from 'moment'
  import ViewFileModal from '@/views/scy/components/ViewFileModal';
  import CommonFlowList from '@/views/components/CommonFlowList.vue';
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
  import { mapGetters } from 'vuex'
  import ErpProjectContractManagerFinalForm from '../../../report/project/modules/ErpProjectContractManagerFinalForm.vue';
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import PaybackDisclaimerDisclaimerInfoList from '../PaybackDisclaimerDisclaimerInfoList.vue';
  import ErpAchievementsExtractionDtList from '../../../omc/achievementsextraction/ErpAchievementsExtractionDtList.vue';
  import Print from '@/utils/print/printarea.js';
  import PaybackDisclaimerFormPrint from './PaybackDisclaimerFormPrint' // 打印
  export default {
    name: 'PaybackDisclaimerForm',
    mixins: [viewFile],
    components: {
      ErpAchievementsExtractionDtList,
      PaybackDisclaimerDisclaimerInfoList,
      ErpProjectContractManagerFinalForm,
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput,
      SelectProjectInput,
      SelectContractManagerInput,
      ViewFileModal,
      CommonFlowList,
      ErpProjectReportModal,
      PaybackDisclaimerFormPrint
    },
    props: {
      // 流程表单data
      formData: {
        type: Object,
        default: () => {},
        required: false
      },
      // 表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          projectId: [
            { required: true, message: '请选择项目名称!' }
          ],
          reason: [
            { required: true, message: '请输入无法按期回款原因!' }
          ]
        },
        url: {
          add: '/api/erp/audit/paybackDisclaimer/paybackDisclaimer/add',
          edit: '/api/erp/audit/paybackDisclaimer/paybackDisclaimer/edit',
          queryById: '/api/erp/audit/paybackDisclaimer/paybackDisclaimer/queryById',
          queryProjectById: '/api/erp/project/report/erpProjectReport/queryById',
          queryContractFinal: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/listForAudit', // 合同档案
          queryXXXXList: '/api/erp/progress/erpProgressPayment/listForAudit', // 收款进度
          queryProjectTaskFinal: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList', // 任务档案
          getBillNo: '/api/erp/audit/paybackDisclaimer/paybackDisclaimer/getBillNo',
          queryTaskInfoList: '/api/erp/audit/paybackDisclaimer/paybackDisclaimerTaskInfo/list'
        },
        taskItemColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '业务分类',
            align: 'center',
            dataIndex: 'category',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['categoryName'], text + '')
              }
            }
          },
          {
            title: '合同占比（%）',
            align: 'center',
            dataIndex: 'contractProportion'
          },
          {
            title: '合同分配额（元)',
            align: 'center',
            dataIndex: 'allocationAmount'
          },
          {
            title: '生产团队',
            align: 'center',
            dataIndex: 'productionTeamId',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['teamId'], text + '')
              }
            }
          },
          {
            title: '项目负责人',
            align: 'center',
            dataIndex: 'projectHead',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['empId'], text + '')
              }
            }
          }
        ],
        taskDataSource: [],
        dictOptions: {},
        projectIdBackups: null
      }
    },
    computed: {
      formDisabled() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return true
          }
        }
        return false
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      // 如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
      // 加载数据字典信息
      this.initDictConfig();
    },
    methods: {
      ...mapGetters(['userInfo']),

      async initDictConfig() {
        initDictOptions('erp_omc_team_manager,alias_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamId', res.result)
          }
        })
        initDictOptions('erp_omc_project_task,category_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'categoryName', res.result)
          }
        })
        initDictOptions('erp_employee_file,name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'empId', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
      },

      // 获取编号
      getBillNo() {
        let that = this;
        getAction(this.url.getBillNo, {}).then((res) => {
          if (res.success) {
            let data = res.result.records || res.result
            this.$set(this.model, 'billNo', data);
            // this.$set(this.model, 'bpmBizTitle', this.userInfo().employee.name+'-'+data);
          }
        })
      },

      goDetail(id) {
        this.$refs.contractForm.initData(id);
        this.$refs.contractForm.visible = true;
      },
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectModalForm.getDetail(model);
              that.$refs.projectModalForm.title = '项目一览表';
            }
          })
        })
      },

      add () {
        this.edit(this.modelDefault);
        this.model.proposer = this.userInfo().empId;
        this.model.proposerDeptId = this.userInfo().deptId;
        this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
        this.getBillNo();
        // 子表置空
        this.taskDataSource = []
        this.projectIdBackups = null
      },

      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);

        // 查询任务信息子表数据
        if (this.model.id) {
          getAction(this.url.queryTaskInfoList, { mainId: this.model.id }).then((res) => {
            if (res.success) {
              this.taskDataSource = res.result.records || res.result
            }
          })
        }
        // 加载免责信息子表数据
        if (this.model.id) {
          this.$refs.disclaimerDetailList.loadData(1, this.model.id)
        } else {
          this.$refs.disclaimerDetailList.dataSource = []
        }
        // 如果有项目id说明是编辑页面，就把原始id给它
        if (this.model.projectId) {
          this.projectIdBackups = this.model.projectId
        }

        this.visible = true;
      },
      // 渲染流程表单数据
      showFlowData() {
        if (this.formBpm === true) {
          let params = { id: this.formData.dataId };
          getAction(this.url.queryById, params).then((res) => {
            if (res.success) {
              this.edit(res.result);
            }
          });
        }
      },

      async projectChangeHandle({ choseObj }) {
      // async projectChangeHandle(data){
        // let backItem = data[0]
        let backItem = choseObj[0]
        // 时间关系 先下面的垃圾代码复制过来用着，有空再提取
        if (!this.projectIdBackups) {
          this.projectIdBackups = this.model.projectId

          this.taskDataSource = []

          // 带出项目编号
          this.$set(this.model, 'projectNo', backItem.finalNo)

          // 带出项目真实名称
          this.$set(this.model, 'projectName', backItem.projectName)

          // 带出项目承接人
          this.$set(this.model, 'undertaker', backItem.undertaker)

          // 带出经营团队
          this.$set(this.model, 'managementTeam', backItem.teamName)

          // 带出业绩归属年度
          this.$set(this.model, 'year', backItem.year)

          // 带出签订单位
          this.$set(this.model, 'signUnit', backItem.signUnit)

          // 带出业主单位
          this.$set(this.model, 'ownerUnit', backItem.ownerUnit)

          // 请求合同档案
          await getAction(this.url.queryContractFinal, { xmmc: backItem.id, htlx: 1 }).then((res) => {
            if (res.success) {
              if (res.result.records.length > 0) {
                // 查出收款合同
                this.$set(this.model, 'contractId', res.result.records[0].id)
                // 带出合同真实名称
                this.$set(this.model, 'contractName', res.result.records[0].htmc)
                // 带出本次合同额
                this.$set(this.model, 'contractAmount', res.result.records[0].bchte)

                var contractIdTemp = res.result.records[0].id
                // 查询收款进度中节点信息
                getAction(this.url.queryXXXXList, { contractId: contractIdTemp, contractType: '1' }).then((res) => {
                  if (res.success) {
                    let { records } = res.result
                    if (records && records.length > 0) {
                      let firstItem = records[0]
                      // 从进度管理-收款进度主表中带出实收款总额
                      this.$set(this.model, 'totalAmountReceived', firstItem.realCollectionPaymentMoney)
                    }
                  }
                })
              } else {
                // 没有收款合同则收款合同带出的信息置空
                this.$set(this.model, 'contractId', '') // 合同id置空
                this.$set(this.model, 'contractName', '') // 合同名称置空
                this.$set(this.model, 'contractAmount', '') // 本次合同额置空
                this.$set(this.model, 'totalAmountReceived', '') // 收款进度-实收款总额置空
              }
            }
          })

          // 请求任务档案根据项目id
          await getAction(this.url.queryProjectTaskFinal, { projectId: backItem.id }).then((res) => {
            if (res.success) {
              if (res.result.records.length > 0) {
                // 生产团队拼接数据
                let teamTextTemp = []
                let teamIdTemp = []

                // 添加任务信息子表数据
                res.result.records.forEach(item => {
                  this.taskDataSource.push({ category: item.id, contractProportion: item.contractRate, allocationAmount: item.contractAmount, productionTeamId: item.productTeam, projectHead: item.projectLeading })
                  if (item.productTeam) {
                    // 生产团队id
                    teamIdTemp.push(item.productTeam);
                    // 生产团队文本
                    teamTextTemp.push(filterMultiDictText(this.dictOptions['teamId'], item.productTeam + ''))
                  }
                })
                if (teamIdTemp && teamIdTemp.length > 0 || teamTextTemp && teamTextTemp.length > 0) {
                  let productTeamId = teamIdTemp.join(',')
                  let productTeamText = teamTextTemp.join(',')
                  this.$set(this.model, 'productionTeam', productTeamText);
                  this.$set(this.model, 'productionTeamId', productTeamId)
                }
              }
            }
          })
        }

        // 切换项目清空子表弹窗提示
        if (this.projectIdBackups && this.projectIdBackups !== backItem.id) {
          let detailList = this.$refs.disclaimerDetailList.submitForm()
          // if (detailList.length > 0){
            const that = this;
            this.$confirm({
              title: '确认切换项目',
              content: '切换项目会清空免责信息数据，您确定要切换吗?',
              okText: '确定',
              cancelText: '取消',
              onOk: async function () {
                // 确认后进行改变
                that.projectIdBackups = that.model.projectId

                // 清空免责信息子表数据
                that.$refs.disclaimerDetailList.dataSource = []
                // 清空任务信息子表数据
                that.taskDataSource = []

                // 带出项目编号
                that.$set(that.model, 'projectNo', backItem.finalNo)

                // 带出项目真实名称
                that.$set(that.model, 'projectName', backItem.projectName)

                // 带出项目承接人
                that.$set(that.model, 'undertaker', backItem.undertaker)

                // 带出经营团队
                that.$set(that.model, 'managementTeam', backItem.teamName)

                // 带出业绩归属年度
                that.$set(that.model, 'year', backItem.year)

                // 带出签订单位
                that.$set(that.model, 'signUnit', backItem.signUnit)

                // 带出业主单位
                that.$set(that.model, 'ownerUnit', backItem.ownerUnit)

                // 请求合同档案
                await getAction(that.url.queryContractFinal, { xmmc: backItem.id, htlx: 1 }).then((res) => {
                  if (res.success) {
                    if (res.result.records.length > 0) {
                      // 查出收款合同
                      that.$set(that.model, 'contractId', res.result.records[0].id)
                      // 带出合同真实名称
                      that.$set(that.model, 'contractName', res.result.records[0].htmc)
                      // 带出本次合同额
                      that.$set(that.model, 'contractAmount', res.result.records[0].bchte)

                      var contractIdTemp = res.result.records[0].id
                      // 查询收款进度中节点信息
                      getAction(that.url.queryXXXXList, { contractId: contractIdTemp, contractType: '1' }).then((res) => {
                        if (res.success) {
                          let { records } = res.result
                          if (records && records.length > 0) {
                            let firstItem = records[0]
                            // 从进度管理-收款进度主表中带出实收款总额
                            that.$set(that.model, 'totalAmountReceived', firstItem.realCollectionPaymentMoney)
                          }
                        }
                      })
                    } else {
                      // 没有收款合同则收款合同带出的信息置空
                      that.$set(that.model, 'contractId', '') // 合同id置空
                      that.$set(that.model, 'contractName', '') // 合同名称置空
                      that.$set(that.model, 'contractAmount', '') // 本次合同额置空
                      that.$set(that.model, 'totalAmountReceived', '') // 收款进度-实收款总额置空
                    }
                  }
                })

                // 请求任务档案根据项目id
                await getAction(that.url.queryProjectTaskFinal, { projectId: backItem.id }).then((res) => {
                  if (res.success) {
                    if (res.result.records.length > 0) {
                      // 生产团队拼接数据
                      let teamTextTemp = []
                      let teamIdTemp = []

                      // 添加任务信息子表数据
                      res.result.records.forEach(item => {
                        that.taskDataSource.push({ category: item.id, contractProportion: item.contractRate, allocationAmount: item.contractAmount, productionTeamId: item.productTeam, projectHead: item.projectLeading })
                        // //项目负责人文本
                        if (item.productTeam) {
                          // 生产团队id
                          teamIdTemp.push(item.productTeam);
                          // 生产团队文本
                          teamTextTemp.push(filterMultiDictText(that.dictOptions['teamId'], item.productTeam + ''))
                        }
                      })

                      // 团队逗号拼接
                      if (teamIdTemp && teamIdTemp.length > 0 || teamTextTemp && teamTextTemp.length > 0) {
                        let productTeamId = teamIdTemp.join(',')
                        let productTeamText = teamTextTemp.join(',')
                        that.$set(that.model, 'productionTeam', productTeamText);
                        that.$set(that.model, 'productionTeamId', productTeamId)
                      }
                    }
                  }
                })

                that.$refs.disclaimerDetailList.showAdd = false
              },
              onCancel() {
                that.model.projectId = that.projectIdBackups
              }
            });
        }
      },

      // 收款合同选择回调
      contractIdBack(item) {},

      submitForm(type) {
        const that = this;
        if (type == 'draft') {
          // 代表保存草稿不做校验
          this.submit(type)
        } else if (type == 'submit') {
          // 免责信息
          let disclaimerInfoList = this.$refs.disclaimerDetailList.submitForm()

          if (!disclaimerInfoList.length > 0) {
            this.$message.warning('请添加免责信息！');
            this.$emit('unButtonDisable');
            return
          }
          // 触发表单验证
          this.$refs.form.validate(valid => {
            if (valid) {
              that.submit(type)
            } else {
              that.$emit('unButtonDisable')
            }
          })
        } else {
          console.log('传参数，保存：draft，提交：submit')
        }
      },
      submit (type) {
        const that = this;
        that.confirmLoading = true;
        let httpurl = '';
        let method = '';
        if (!this.model.id) {
          httpurl += this.url.add;
          method = 'post';
        } else {
          httpurl += this.url.edit;
          method = 'put';
        }
        var projectName = filterMultiDictText(this.dictOptions['projectId'], this.model.projectId + '')
        this.$set(this.model, 'bpmBizTitle', '回款免责申请单-' + (this.model.projectId ? projectName + '-' : '') + this.userInfo().employee.name + '-' + moment(this.model.createTime).format('YYYY-MM-DD'));
        this.model.disclaimerInfoList = this.$refs.disclaimerDetailList.submitForm() || []
        this.model.taskInfoList = this.taskDataSource || []
        httpAction(httpurl, this.model, method).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            if (method == 'post') {
              that.model.id = res.result;
            }
            that.$emit('ok', type, that.model);
          } else {
            that.$message.warning(res.message);
            that.$emit('unButtonDisable');
          }
        }).catch((error) => {
          that.$emit('unButtonDisable', error);
        }).finally(() => {
          that.confirmLoading = false;
        })
      },

      // 点击打印
      onPrint () {
        let print = new Print({
          el: '#paybackDisclaimer',
          popTitle: '回款免责申请详情 · 禾美环保',
          endCallback() {

          }
        })
      }
    }
  }
</script>
